package homework;

import java.io.*;
import java.util.Scanner;

public class Test03 {
    public static void main(String[] args) throws IOException {

        Scanner input = new Scanner(System.in);
        System.out.println("请输入你的姓名");
        String name = input.nextLine();
        System.out.println("请输入你的登录密码");
        String pwd = input.nextLine();
        System.out.println("请输入你的nick");
        String nick = input.nextLine();
        System.out.println("请输入你的年龄");
        int age = input.nextInt();
        if(name.matches("[a-zA-Z0-9_]{1,33}")&&pwd!=null&&nick!=null&&age>0&&age<100){
            User user = new User(name,pwd,nick,age);
            File file = new File(name+".obj");
            if(!file.exists()) {file.createNewFile();System.out.println("文件创建成功");}
            OutputStream is = new FileOutputStream(name+".obj");
            ObjectOutputStream oos = new ObjectOutputStream(is);
            oos.writeObject(user);
            System.out.println("对象序列化成功");
        }else {
            System.out.println("您的信息不符，请重新访问");
            return;
        }

    }
}

